package com.sl.wf.controller;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sl.wf.entity.UserEntity;
import com.sl.wf.service.UserService;


@EnableAutoConfiguration
@RestController
@RequestMapping("/user")
public class UserController {
	@Autowired
	private UserService userService;

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public InUser add(@Valid @RequestBody final InUser inUser) {

		userService.addUser(inUser);
		return inUser;
	}



	@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
	public InUser delete(@Valid @RequestBody final InUser inUser) {
		userService.deleteUser(inUser.getId());
		return inUser;

	}

	//	@RequestMapping("/update")
	//	public InUser update(@Valid @RequestBody final InUser inUser) {
	//		//		inUser.setId(00);
	//		//		inUser.setName("bbb");
	//		//		inUser.setAge(10);
	//		userService.updateUser(inUser);
	//		return inUser;
	//	}
	@RequestMapping(value = "/update", method = RequestMethod.PUT)
	public InUser update(@Valid @RequestBody final InUser inUser) {
		//		inUser.setId(00);
		//		inUser.setName("bbb");
		//		inUser.setAge(10);
		userService.updateUser(inUser.getId(), inUser);
		return inUser;
	}

	@RequestMapping(value = "/select/{id}", method = RequestMethod.GET)
	public UserEntity select(@PathVariable final Integer id) {
		final UserEntity userEntity = userService.selectUser(id);
		return userEntity;

	}
}
